<?php

namespace Kunfeng\Dify\Model\Datasets;

/**
 * 创建文档请求模型
 */
class CreateDocumentRequest
{
    private $name;
    private $text;
    private $indexingTechnique;
    private $processRule;
    private $docForm;
    private $docLanguage;
    private $retrievalModel;
    private $embeddingModel;
    private $embeddingModelProvider;

    public function __construct(
        string $name,
        string $text,
        string $indexingTechnique = 'high_quality',
        ?ProcessRule $processRule = null,
        string $docForm = 'text_model',
        string $docLanguage = 'Chinese',
        ?RetrievalModel $retrievalModel = null,
        ?string $embeddingModel = null,
        ?string $embeddingModelProvider = null
    ) {
        $this->name = $name;
        $this->text = $text;
        $this->indexingTechnique = $indexingTechnique;
        $this->processRule = $processRule;
        $this->docForm = $docForm;
        $this->docLanguage = $docLanguage;
        $this->retrievalModel = $retrievalModel;
        $this->embeddingModel = $embeddingModel;
        $this->embeddingModelProvider = $embeddingModelProvider;
    }

    /**
     * 创建请求
     */
    public static function create(string $name, string $text): self
    {
        return new self($name, $text);
    }

    /**
     * 转换为数组
     */
    public function toArray(): array
    {
        $data = [
            'name' => $this->name,
            'text' => $this->text,
            'indexing_technique' => $this->indexingTechnique,
            'doc_form' => $this->docForm,
            'doc_language' => $this->docLanguage,
        ];

        if ($this->processRule !== null) {
            $data['process_rule'] = $this->processRule->toArray();
        }
        if ($this->retrievalModel !== null) {
            $data['retrieval_model'] = $this->retrievalModel->toArray();
        }
        if ($this->embeddingModel !== null) {
            $data['embedding_model'] = $this->embeddingModel;
        }
        if ($this->embeddingModelProvider !== null) {
            $data['embedding_model_provider'] = $this->embeddingModelProvider;
        }

        return $data;
    }

    // Getters
    public function getName(): string
    {
        return $this->name;
    }

    public function getText(): string
    {
        return $this->text;
    }

    public function getIndexingTechnique(): string
    {
        return $this->indexingTechnique;
    }

    public function getProcessRule(): ?ProcessRule
    {
        return $this->processRule;
    }

    public function getDocForm(): string
    {
        return $this->docForm;
    }

    public function getDocLanguage(): string
    {
        return $this->docLanguage;
    }

    public function getRetrievalModel(): ?RetrievalModel
    {
        return $this->retrievalModel;
    }

    public function getEmbeddingModel(): ?string
    {
        return $this->embeddingModel;
    }

    public function getEmbeddingModelProvider(): ?string
    {
        return $this->embeddingModelProvider;
    }
}
